package com.linsy.product.redis.mq.entity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import lombok.Data;

import java.util.LinkedHashMap;

@Data
public class MqDataVO {

    private Long rowId;

    /**
     * 发送数据（JSON字符串）
     */
    private String mqData;

    public static MqDataVO objectToVO(Object items) {
        if (items == null) {
            return null;
        }
        MqDataVO vo = null;
        if (items instanceof LinkedHashMap) {
            vo = new MqDataVO();
            LinkedHashMap hashMap = (LinkedHashMap) items;
            Object mqData = hashMap.get("mqData");
            if (mqData != null) {
                vo.setMqData((String) mqData);
            }
        } else {
            vo = JSON.parseObject(JSON.toJSONString(items), new TypeReference<MqDataVO>() {
            });
        }

        return vo;
    }
}
